<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Hello World</title>
  <script src="https://unpkg.com/vue"></script>
</head>

<body>
  <div id="root"></div>
  <script>
    /* 
      1. data中定义数据
      2. vm.xxx或vm.$data.xxx或this.xxx 修改数据
      3. methods中定义方法
      4. 方法中this指向vue实例
      5. 计算属性computed
      6. 计算属性和methods中方法的区别
      操作：
      - 控制台中修改msg值，查看computed和methods区别
    */
    const app = Vue.createApp({
      template: `<div>
        <h3>{{msg}} -- {{getResult()}}</h3>
        <h3>{{msg}} -- {{result}}</h3>
        <button @click="handleClick">修改</button>
      </div>`,
      data() {
        return {
          msg: `Hello World`,
          count: 1,
          price: 5
        }
      },
      computed: {
        result() {
          return Date.now()
          return this.count * this.price
        }
      },
      methods: {
        handleClick() {
          this.count++;
          return
        },
        getResult() {
          // 页面重新计算
          return Date.now()
          return this.count * this.price
        }
      }
    })
    const vm = app.mount('#root');
  </script>
</body>

</html>